﻿using MediatR;
using T_Person.BaseRep.Interface;
using T_Person.Read.APi.Applaction.Command.Employment;
using T_Person.Read.APi.Dto;

namespace T_Person.Read.APi.Applaction.CommandHandlers.PersonnelHandlers
{
    public class EmployeeSearchStateArrayByidHandlers : IRequestHandler<EmployeeSearchStateArrayByidCommand, StateArray>
    {
        private readonly IEmployeeRep employeeRep;
        private readonly IPersonnelRep personnelRep;

        public EmployeeSearchStateArrayByidHandlers(IEmployeeRep employeeRep, IPersonnelRep personnelRep)
        {
            this.employeeRep = employeeRep;
            this.personnelRep = personnelRep;
        }

        public async Task<StateArray> Handle(EmployeeSearchStateArrayByidCommand request, CancellationToken cancellationToken)
        {
            var list = await personnelRep.GetAloneByid(request.id);
            if (list != null)
            {
                var employeelist = await employeeRep.GetAloneByresult(x => x.Ename == list.EmployeeId && !x.IsDel);
                var lista = new StateArray()
                {
                    id = employeelist.Eid,
                    state = employeelist.EmployeeStyle,
                };
                return lista;
            }
            return new StateArray();
        }
    }
}
